<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta http-equiv="x-ua-compatible" content="ie=edge">
		<title>实名认证</title>
		<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
		<link rel="stylesheet" href="information.css">
		<link rel="stylesheet" href="../public_css/public_header.css">

		<script src="../public/jquery.min.js"></script>
		<script src="../public/layer.js"></script>
		<script src="../public_js/public_js.js"></script>
		<!-- <script src="../js/order/info/information.js"></script>  -->
	</head>

	<body>
		<header class=" public_header">
			<div class="public_header_return">
				<img src="../public_img/return.png" alt="" class="public_header_return" onclick="history.back(-1)">
				<p>实名认证</p>
			</div>
		</header>
		<section class="mainbody">
			<section class="head_portrait"><img id="headImage" src="http://image.icandrive.cn/herderimg.jpg">
				<input type="file" onchange="UpladFile()" name="file" class="file" id="file" size="28" style="display: none" />
			</section>
			<form class="information_collect clearfix">
				<span>姓名:</span>
				<input class="message_input" type="text" name="username" id="username">
				<br/>
				<span>身份证号:</span>
				<input class="message_input" type="text" name="idcard" id="idcard">
				<br/>
				<span>职业:</span>
				<input class="message_input" type="text" name="work" id="work">
				<br/>
				<div class="checkbox_default">
					<input type="checkbox" id="drive_argument" name="drive_argument">我已阅读并同意《i驾车报名协议》
					<label id="label_btn" for="drive_argument"></label>
				</div>
				<br/>
				<input class="submit_final" id="regBtn" type="button" value="提交">
			</form>
		</section>

	</body>
        <script type="text/javascript">
            var flag=false;
            $('#headImage').click(function () {
                $('#file').click();
            });
            function createXMLHttpRequest() {
                if (window.ActiveXObject) {
                    xhr = new ActiveXObject("Microsoft.XMLHTTP");
                } else if (window.XMLHttpRequest) {
                    xhr = new XMLHttpRequest();
                }
            }

            function UpladFile() {
                var f=document.getElementById("file").value;
                if(!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(f))
                {
                    layer.msg("请选择正确格式的图片");
                    return false;
                }
                var token=localStorage.phone;
                var fileObj = document.getElementById("file").files[0];
                var FileController = 'https://newapp.icandrive.cn/api/student_photo.php?token='+token;
                var form = new FormData();
                form.append("myfile", fileObj);
                createXMLHttpRequest();
                xhr.onreadystatechange = handleStateChange;
                xhr.open("post", FileController, true);
                xhr.send(form);
            }

            function handleStateChange() {
                if (xhr.readyState == 4) {
                    if (xhr.status == 200 || xhr.status == 0) {
                        var result = xhr.responseText;
                        var json = eval("(" + result + ")");
                        $("#headImage").prop('src',json);
                        flag=true;
                    }
                }
            }
            $(".information_btn1").click(function(){
                history.back();
            });



            $("#username").blur(function(){
                var username = $("#username").val();
                if(username==""){
                    layer.msg("姓名不能为空");
                    return false;
                }
            });
            $("#idcard").blur(function(){
                var idcard = $("#idcard").val();
                if(idcard==""){
                    layer.msg("请输入身份证号码");
                    return false;
                }else if (!/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/i.test(idcard)){
                    layer.msg("请填写合法的身份证号");
                    return false;
                }
            });
            $("#work").blur(function(){
                var work = $("#work").val();
                if(work  ==""){
                    layer.msg("职业不能为空");
                    return false;
                }
            });
            $(".submit_final").click(function(){
				var photo = $("#headImage").prop('src');
                var token =localStorage.phone;
                var username = $("#username").val();
                if(username==""){
                    layer.msg("姓名不能为空");
                    return false;
                }
                var idcard = $("#idcard").val();
                if(idcard==""){
                    layer.msg("身份证不能为空");
                    return false;
                }
                var work = $("#work").val();
                if(work==""){
                    layer.msg("职业不能为空");
                    return false;
                }
                if(!$('#drive_argument').prop('checked')){
                    layer.msg("请先阅读i驾车报名协议");
                    return false;
                }


                $.ajax({
                    url:"https://newapp.icandrive.cn/api/saveUserInfo.php",
                    type:'post',
                    dataType:'json',
                    data:{token:token,user_name:username,id_number:idcard,work:work,photo:photo},
                    success:function(data){
                        if(data.status==402){
                            layer.msg("认证系统服务关闭");
                        }
                        if(data.status==403){
                            layer.msg("身份信息不匹配");
                        }
                      if(data.status==450){
                            layer.msg("不能重复提交");
                        }
                        if(data.status==200){
                            layer.msg("认证成功");
                            setInterval(function(){
                                window.location.href="../index/index.html";
                            },2000);
                        }
                        if(data.status==250){
                            layer.msg("请重新登录");
                            setInterval(function(){
                                window.location.href="../login/log_in.html";
                            },2000);
                        }
                        if(data.status==400){
                            layer.msg("认证失败，请重新认证");
                        }
                    },
                    error:function(){
                        layer.msg('系统维护中');
                    }
                });
            });

        </script>

        <script>
            document.addEventListener("plusready", function() {
                // 注册返回按键事件
                plus.key.addEventListener('backbutton', function() {
                    window.history.back();
                }, false);
                //此处false代表不退出页面，如果为true回退到上一个一面
            });
        </script>
</html>
